#include <iostream>
#include <string>
#include <math.h>
using namespace std;
class Figure {
public:
    virtual string getName() const = 0;
    virtual double getArea() const = 0;
};
class Rectangle : public Figure{
public:
    Rectangle(int x,int y)
    :_x(x)
    ,_y(y){}
    string getName() const override{
          return "长方形";
    }
    double getArea() const override{
       return _x *_y;
    }
private:
    int _x;
    int _y;
};
class Circle : public Figure{
public:
    Circle(int ridus)
    :_ridus(ridus){}
    string getName()const override{
        return "圆形";
    }
    double getArea()const override{
        return 3.14 * _ridus *_ridus;
    }
private:
    int _ridus;
};
class Triangle : public Figure{
public:
    Triangle(int x,int y,int z)
    :_x(x)
    ,_y(y)
    ,_z(z){}
    string getName()const override{
        return "三角形";
    }
    double getArea()const override{
        double p = (_x+_y+_z)/2;
         return sqrt(p*(p-_x)*(p-_y)*(p-_z));
    }
private:
    int _x;
    int _y;
    int _z;
};
void display(Figure & fig) {
    cout << fig.getName() 
         << "的面积是:" 
         << fig.getArea() << endl ;
}

void test() {
    Rectangle r(10, 20);
    Circle c(15);
    Triangle t(3, 4, 5);
    display(r);
    display(c);
    display(t);
}
int main()
{
    test();
    return 0;
}

